from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.pagination import PageNumberPagination
from .models import Table,Title
from .serializers import TableSerializer, TitleSerializer


class TableDataView(APIView):
    def get(self, request):
        paginator = PageNumberPagination()
        paginator.page_size = 100  # 设置每页的记录数

        tables = Table.objects.all()
        result_page = paginator.paginate_queryset(tables, request)
        serializer = TableSerializer(result_page, many=True)
        return paginator.get_paginated_response(serializer.data)

class TitleView(APIView):
    def get(self, request):
        titles = Title.objects.all()
        serializer = TitleSerializer(titles, many=True)
        return Response(data=serializer.data)